package com.xinpu.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinpu.dto.PhotoDto;
import com.xinpu.entity.TPhotoBrowse;
import com.xinpu.vo.PhotoVo;
import com.xinpu.vo.SalesPhotoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * PhotoMapper
 *
 * @author ayuan
 * @date 2021/5/11
 */
@Repository
public interface PhotoMapper {

    /**
     * 图文列表
     *
     * @param page
     * @return
     */
    IPage<PhotoDto> getList(Page<PhotoDto> page, String name, Integer cid);

    /**
     * 图文总数
     *
     * @param id
     * @return
     */
    @Select("SELECT\n" +
            "\tt_photo.title, t_photo.id,\n" +
            "\t( SELECT count( 1 ) FROM t_sales_photo WHERE pid = #{id} )  count,\n" +
            "\t(SELECT\tsum(num) FROM t_sales_photo WHERE pid=#{id}) num\n" +
            "FROM\n" +
            "\tt_photo\n" +
            "\tWHERE id=#{id}\n")
    PhotoVo photo(Integer id);

    /**
     * 销售员转发此图文的浏览信息
     *
     * @param id
     * @return
     */
    @SqlParser(filter = true)
    IPage<SalesPhotoVo> salesPhoto(Integer id, String name, IPage<SalesPhotoVo> page);

    @SqlParser(filter = true)
    Integer num(@Param("tenantId") String tenantId, @Param("date") String date);

    @SqlParser(filter = true)
    IPage<TPhotoBrowse> photoList(@Param("id") Integer id, @Param("tenantId") String tenantId, IPage<TPhotoBrowse> page);

}
